/**
 * Copyright 2020 OPSLI 快速开发平台 https://www.opsli.com
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package org.opsli.modulars.business.emergency.service.impl;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.opsli.api.wrapper.business.emergency.EmergencyReportModel;
import org.opsli.api.wrapper.system.user.UserModel;
import org.opsli.modulars.business.emergency.entity.ConvexModel;
import org.opsli.modulars.business.emergency.entity.LineSpotName;
import org.opsli.modulars.business.emergency.entity.LineSpotTreeMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.opsli.core.base.service.impl.CrudServiceImpl;

import org.opsli.modulars.business.emergency.entity.EmergencyReport;
import org.opsli.modulars.business.emergency.service.IEmergencyReportService;
import org.opsli.modulars.business.emergency.mapper.EmergencyReportMapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 应急事件 Service Impl
 *
 * @author zk
 * @date 2021-09-15 13:51:58
 */
@Service
public class EmergencyReportServiceImpl extends CrudServiceImpl<EmergencyReportMapper, EmergencyReport, EmergencyReportModel>
    implements IEmergencyReportService {

    @Autowired(required = false)
    private EmergencyReportMapper mapper;

    @Override
    public List<EmergencyReportModel> findList(String devid){
        return mapper.findList(devid);
    }

    @Override
    public List<EmergencyReportModel> findListAll(String devid){
        return mapper.findListAll(devid);
    }

    @Override
    public List<EmergencyReportModel> findListByProjectId(String projectId) {
        return mapper.findListByProjectId(projectId);
    }

    @Override
    public Page<EmergencyReport> getMyList(Page<EmergencyReport> page, EmergencyReport announcementSendModel,Integer beginSize,Integer endSize){
        return page.setRecords(mapper.getMyList(announcementSendModel,beginSize,endSize));
    }

    @Override
    public Page<EmergencyReport> getMyListNew(Page<EmergencyReport> page, EmergencyReport announcementSendModel, Integer beginSize, Integer endSize) {
        return page.setRecords(mapper.getMyListNew(announcementSendModel,beginSize,endSize));
    }

    @Override
    public List<EmergencyReport> getWeekList(String devid){
        return mapper.getWeekList(devid);
    }

    @Override
    public ConvexModel getConvexList(String devid) {
        ConvexModel cmodel=new ConvexModel();
        String todayLine=mapper.getTodayLine(devid).toString();
        String monthLine=mapper.getMonthLine(devid).toString();
        String todaySpot=mapper.getTodaySpot(devid).toString();
        String monthSpot=mapper.getMonthSpot(devid).toString();
        String todayEmergency=mapper.getTodayEmergency(devid).toString();
        String monthEmergency=mapper.getMonthEmergency(devid).toString();
        cmodel.setTodayLine(todayLine);
        cmodel.setMonthLine(monthLine);
        cmodel.setTodaySpot(todaySpot);
        cmodel.setMonthSpot(monthSpot);
        cmodel.setTodayEmergency(todayEmergency);
        cmodel.setMonthEmergency(monthEmergency);
        return cmodel;
    }

    @Override
    public LineSpotName getListMap(String devid) {
        LineSpotName lineSpotName=new LineSpotName();

        List<UserModel> userList=mapper.findListName(devid);
        String[]  name=new String[userList.size()];
        String[]  line=new String[userList.size()];
        String[]  port=new String[userList.size()];
        int i=0;
        for (UserModel um:userList){
            //根据name值去查任务表里的巡线次数
            LineSpotTreeMap lineList=mapper.getLine(devid,um.getRealName());
            if(null!=lineList){
                line[i]=lineList.getCount();//次数
            }else {
                line[i]="";
            }
            LineSpotTreeMap spotList=mapper.getSpot(devid,um.getRealName());
            if(null!=spotList){
                port[i]=spotList.getCount();//次数
            }else {
                port[i]="";
            }
            name[i]=um.getRealName();
            i++;
        }
        lineSpotName.setName(name);
        lineSpotName.setLine(line);
        lineSpotName.setPort(port);

        return lineSpotName;
    }

}
